package cn.wjboot.core.web.service;

import com.anji.captcha.service.CaptchaCacheService;
import cn.wjboot.core.utils.redis.RedisUtils;

import java.time.Duration;

/**
 * 自定义redis验证码缓存实现类
 *
 * @author ruoyi
 */
public class CaptchaRedisService implements CaptchaCacheService
{

    @Override
    public void set(String key, String value, long expiresInSeconds)
    {
        RedisUtils.setCacheObject(key, value, Duration.ofSeconds(expiresInSeconds));
    }

    @Override
    public boolean exists(String key)
    {
        return RedisUtils.hasKey(key);
    }

    @Override
    public void delete(String key)
    {
        RedisUtils.deleteObject(key);
    }

    @Override
    public String get(String key)
    {
        return RedisUtils.getCacheObject(key);
    }

    @Override
    public Long increment(String key, long val)
    {
        return RedisUtils.increment(key,val);
    }

    @Override
    public String type()
    {
        return "redis";
    }
}
